from pymysql import *


def main():
    # 创建connection链接
    conn = connect(host="localhost",port=3306,user="root",password="mysql",database="jing_dong",charset="utf8")
    # 获取cursor对象
    cs1 = conn.cursor()

    # 执行select 语句，返回受影响的行数，查询一条语句
    count = cs1.execute("select id ,name from goods where id>4")

    # 打印受影响的行数
    print("查询到的%d条数据:" % count)

    # for...in...遍历 结果集
    for i  in range(count):
        # 获取查询的结果
        result = cs1.fetchone()

        # 打印查询的结果
        print(result)

    # 关闭cursor对象
    cs1.close()

    # 关闭链接
    conn.close()




if __name__ == "__main__":
    main()
